//
// Created by xili on 2024/8/22 15:38.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minimumRecolors(string blocks, int k) {

        int cur = 0, i = 0;
        int n = blocks.size();
        while (i < k) {
            cur += is(blocks[i++]);
        }
        int ans = cur;
        while (i < n) {
            cur += is(blocks[i]) - is(blocks[i - k]);
            i++;
            ans = max(ans, cur);
        }
        return k - ans;
    }

    bool is(char c) {
        return c == 'B';
    }
};